const socket=io();
const chantMessages=document.querySelector('.mains_right')
const chatfrom=document.querySelector('.chatfrom')
var indexParm
var time = new Date();
let lists={
    name:'mary',
    home:'javascript'
  }
socket.on('des',(des)=>{
    outputMessage(des)
    console.log(des)
    //滚顶条
    console.log(chantMessages.scrollTop)
    chantMessages.scrollTop=chantMessages.scrollHeight
})
chatfrom.addEventListener('submit',r=>{
  r.preventDefault()
  const indexMsg=r.target.elements.msg.value
    indexParm={
    name:lists.name,
    home:lists.home,
    text:indexMsg,
    time:time.toLocaleString( )
  }
  outputMessage(indexParm)
  socket.emit('chatDes',indexParm)
})
function outputMessage(des){
    $('.mains_right').append(
        `
   <div class="information">
   <div class="top">${des.name} <p>${des.time}</p></div>

   <p class="chat_mass">
     ${des.text}
   </p>
</div> `
    )

    
   
}


